import { getOrders } from '@/api/getOrderList'
import moment from 'moment'
const order = {
  state: {
    orderListMenu: sessionStorage.getItem('orderListMenu') || '1',
    orderDataList: [],
    orderParams: {
      hoperatorId: '', // 经营者id
      storesId: '', // 门店id
      jylx: '', // 门店所属经营类型
      page: 1, // 页码
      gjc: '', // 关键字
      ddzt: sessionStorage.getItem('orderListMenu') || 1,
      jsrq: sessionStorage.getItem('orderListMenu') === '2' ? moment().format('YYYY-MM-DD') : '',
      ksrq: sessionStorage.getItem('orderListMenu') !== '2' && sessionStorage.getItem('orderListMenu') !== '0' ? moment().format('YYYY-MM-DD') : '',
      pagesize: 10 // 显示条数
    },
    orderLoading: false,
    orderTotal: 0
  },
  mutations: {
    setorderListMenu (state, data) {
      sessionStorage.setItem('orderListMenu', data)
      state.orderListMenu = data
    },
    setOrderDataList (state, data) {
      state.orderDataList = data
    },
    setOrderParams (state, data) {
      state.orderParams = Object.assign(state.orderParams, data)
    },
    setOrderLoading (state, data) {
      state.orderLoading = data
    },
    setOrderTotal (state, data) {
      state.orderTotal = data
    }
  },
  actions: {
    getorderListMenuMsg ({ commit }, data) {
      commit('setOrderLoading', true)
      return new Promise((resolve, reject) => {
        try {
          getOrders(data).then((res) => {
            commit('setOrderDataList', res.data)
            commit('setOrderTotal', res.count)
            commit('setOrderLoading', false)
            resolve(res)
          }).catch(error => reject(error))
        } catch (error) {
          reject(error)
        }
      })
    }
  }
}
export default order
